// ChildFrm.cpp : implementation of the CChildFrame class
//

#include "stdafx.h"
#include "waveeditor.h"
#include "MainFrm.h"

#include "ChildFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChildFrame

IMPLEMENT_DYNCREATE(ChildTreeFrame, CMDIChildWnd)

BEGIN_MESSAGE_MAP(ChildTreeFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(CChildFrame)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
	ON_WM_SIZING()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChildFrame construction/destruction

ChildTreeFrame::ChildTreeFrame()
{
	// TODO: add member initialization code here
	
}

ChildTreeFrame::~ChildTreeFrame()
{
}

BOOL ChildTreeFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	CRect framerect;
	CRect srect;
	CRect trect;

	ParentMainFrame *pMainFrame = (ParentMainFrame *) AfxGetMainWnd();
	pMainFrame->GetClientRect(&framerect);
	pMainFrame->m_wndStatusBar	.GetWindowRect(&srect);
	pMainFrame->m_wndToolBar	.GetWindowRect(&trect);
	int	height	=	framerect.Height()-srect.Height()*2-trect.Height();
	cs.x		=	framerect.left;
	cs.y		=	framerect.top;
	cs.cx		=	framerect.right/4;
	cs.cy		=	height - DEBUG_WINDOW_HEIGHT;
	cs.style	&= ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX |WS_SYSMENU );
	if( !CMDIChildWnd::PreCreateWindow(cs) )
			return FALSE;
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CChildFrame diagnostics

#ifdef _DEBUG
void ChildTreeFrame::AssertValid() const
{
	CMDIChildWnd::AssertValid();
}

void ChildTreeFrame::Dump(CDumpContext& dc) const
{
	CMDIChildWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChildFrame message handlers


int ChildTreeFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
//	CMainFrame *mFrame = (CMainFrame*) AfxGetMainWnd()->m_hWnd;
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.Load24BitToolBar( IDR_TREEVIEWFRAME, IDB_TREEVIEW_TOOLBAR_DISABLED ))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}


	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	return 0;
}

void ChildTreeFrame::OnSizing(UINT fwSide, LPRECT pRect)
{
	CMDIChildWnd::OnSizing(fwSide, pRect);
	CRect framerect;
	CRect srect;
	CRect trect;

	// TODO: Add your message handler code here
	ParentMainFrame *pMainFrame = (ParentMainFrame *) AfxGetMainWnd();
	pMainFrame->GetClientRect(&framerect);
	pMainFrame->m_wndStatusBar	.GetWindowRect(&srect);
	pMainFrame->m_wndToolBar	.GetWindowRect(&trect);
	int	height	=	framerect.Height()-srect.Height()*2-trect.Height();
	RECT	cs;
	cs.left		=	framerect.left;
	cs.top		=	framerect.top;
	cs.right	=	framerect.left + framerect.right / 4;
	cs.bottom	=	framerect.top + height - DEBUG_WINDOW_HEIGHT;
	MoveWindow(&cs);
}
